package cn.itcast.demo.interceptors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class LoginInterceptor implements HandlerInterceptor {


    //产生一个日志的对象
    Logger logger = LoggerFactory.getLogger(LoginInterceptor.class);


    //决定拦截器是否生效 true，生效
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        logger.info("当前正在执行{}方法","preHandle");
        return true;
    }

    //执行业务完成后再次来到这里要不要什么特殊配置
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        logger.info("当前正在执行{}方法","postHandle");
    }


    //这个拦截器两遍被路过完了，
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        logger.info("当前正在执行{}方法","afterCompletion");
    }
}
